<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/4 0004
 * Time: 09:39
 */
namespace Admin\Controller;

use Admin\Controller\CommonController;

class ExchangeController extends CommonController
{
    public function index()
    {
        $this->display();
    }
    /**
     * 道具兑换列表
     */

    public function buyList(){
        $search = $_POST['search'];
        if(!empty($search)){
            $where['p.title|g.game'] = array(
                'like',
                '%'.$search.'%'
            );
        }
        $data['rows'] = M('ItemExchange')->alias('b')
            ->where($where)
            ->join('left join '.C('DB_PREFIX').'item as p on b.itemid=p.itemid')
            ->join('left join '.C('DB_PREFIX').'game as g on p.gameid=g.gameid')
            ->field('p.title,b.exchangeid,b.pnum,b.cnum,b.status,b.balance,b.createtime,g.game')
            ->page($_POST['page'],$_POST['rows'])
            ->order('b.exchangeid desc')
            ->select();
//        foreach ($buyList as $k=>$v){
//            $data['rows'][$k]['exchangeid'] = $v['exchangeid'];
//            $data['rows'][$k]['title']      = $v['title'];
//            $data['rows'][$k]['pnum']       = $v['pnum'];
//            $data['rows'][$k]['cnum']       = $v['cnum'];
//
//            if($v['status'] == '1'){
//                $data['rows'][$k]['status'] = "已完成";
//            }else{
//                $data['rows'][$k]['status'] = "<span style='color: red'>未完成</span>";
//            }
//
//            $data['rows'][$k]['balance']    = $v['balance'];
//            $data['rows'][$k]['game']       = $v['game'];
//            $data['rows'][$k]['createtime'] = $v['createtime'];
//        }
        $data['total'] = M('item_exchange')->count();
        $this->ajaxReturn($data);
    }

    /**
     *删除道具兑换记录
     */
   /* public function delChange(){
        $where['exchangeid']=array('in',$_POST['id']);
        $option = M('item_exchange')
            ->where($where)
            ->delete();
        if($option){
            $data = [
                'status' => 1,
                'msg' => '数据删除成功'
            ];
        }else{
            $data = [
                'status' => 0,
                'msg' => '数据删除失败'
            ];
        }
        $this->ajaxReturn($data);
    }*/
}

